package com.newly.api.sys.feign;

import com.newly.common.base.constants.ServerUriConstant;
import com.newly.common.base.entity.R;
import com.newly.common.base.entity.sys.auth.role.dto.RoleDto;
import com.newly.common.base.entity.valid.Insert;
import com.newly.common.base.entity.valid.Update;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author gjm guan
 * @date 2021/11/1 15:14
 * @desc 角色管理
 */
@Api(tags = "角色管理")
@FeignClient(path = ServerUriConstant.NEWLY_SYS_ROLE, name = ServerUriConstant.NEWLY_SYS_SERVICE_NAME)
public interface RoleClient {

    @ApiOperation("创建角色")
    @PostMapping("/create")
    R create(@NotNull(message = "No request parameters")
             @Validated(Insert.class) @RequestBody RoleDto roleDto);

    @ApiOperation("修改角色")
    @PutMapping("/change")
    R change(@NotNull(message = "No request parameters")
             @Validated(Update.class) @RequestBody RoleDto roleDto);

    @ApiOperation("通过id删除角色")
    @DeleteMapping("/deleteByIds")
    R deleteByIds(@NotEmpty(message = "roleIds can't be empty") @RequestParam("roleIds") List<Integer> roleIds,
                  @RequestParam(value = "must", required = false) Integer must);

    @ApiOperation("查询角色列表")
    @GetMapping("/list")
    R list(@NotNull(message = "offset can't be empty") @RequestParam("offset") Integer offset,
           @NotNull(message = "limit can't be empty") @RequestParam("limit") Integer limit,
           @RequestParam(value = "createBy", required = false) String createBy,
           @RequestParam(value = "fromTime", required = false) String fromTime,
           @RequestParam(value = "toTime", required = false) String toTime,
           @RequestParam(value = "keyword", required = false) String keyword);

    @ApiOperation("查询当前租户角色")
    @GetMapping("/queryInAuth")
    R queryInAuth();

    @ApiOperation("查询类型列表")
    @GetMapping("/queryTypes")
    R queryTypes();

    @ApiOperation("查询禁用启用状态")
    @GetMapping("/queryEnable")
    R queryEnable();

    @ApiOperation("查询创建人列表")
    @GetMapping("/queryCreateTenant")
    R queryCreateTenant();

    @GetMapping("/queryById")
    R queryById(@NotNull(message = "roleId can't be empty")
                @RequestParam("roleId") Integer roleId);

    @ApiOperation("查询角色的绑定租户")
    @GetMapping("queryBindUserOfRole")
    R queryBindUserOfRole(@RequestParam("roleId") String roleId);

    @ApiOperation("给租户绑定角色")
    @PostMapping("/bind")
    R bind(@NotBlank(message = "tenantId can't be empty") @RequestParam("tenantId") String tenantId,
           @NotBlank(message = "roleId can't be empty") @RequestParam("roleId") String roleId);
}
